require 'View/UIBase/UIBase'

UILongJourneyHellSelectBuff = UIBase.New(PanelResNames.UIExpeditionSelectBuff)
local t = UILongJourneyHellSelectBuff

function t.Init(buffIds,callback)
    t.buffId= buffIds or {}
    t.callback = callback
    UIBase.Init(t)
end

function t:OnCreate()
    self.ctrlBuff = self:GetController("ctrlBuff");
    self.btnSure = self:GetChild("ConfirmButton");
    self.buffItemList = {};
    for k = 1,3 do
        table.insert(self.buffItemList,self:GetChild("Card"..k));
    end

    self:RegisterOnClick(self.btnSure,self.ClickSure);
end

function t:OnEnable()
    self.ctrlBuff.selectedIndex = 0
    self:Refresh()
end
function t:OnDisable()
end
function t:OnDestroy()
end

function t:Refresh()
    local buffNum = #self.buffId;
    for i = 1,3 do
        if i > buffNum then
            self.buffItemList[i].visible = false;
        else
            local cfg = dataTable.getDataTableByStringId("t_buff", self.buffId[i]);
            if cfg == nil then
                self.buffItemList[i].visible = false;
            else
                local nameText = self.buffItemList[i]:GetChild("Title");
                local icon = self.buffItemList[i]:GetChild("Bufficon");
                local tipText = self.buffItemList[i]:GetChild("BuffTips");
                local ctrl= self.buffItemList[i]:GetController("type");
                ctrl.selectedIndex = 2;
                ObjUtil.SetBuffIcon(self.buffId[i],icon,nameText,tipText);
            end
        end
    end
end
function t:ClickClose()
    self:OnBack();
end
function t:ClickSure()
    local index = self.ctrlBuff.selectedIndex
    if index == 0 then return end
    if self.callback ~= nil  then
        self.callback(index);
        self.callback = nil;
    end
    self:ClickClose();
end
return t